package com.soladhoc.annonces.server;

import com.google.inject.Inject;
import com.gwtplatform.dispatch.server.ExecutionContext;
import com.gwtplatform.dispatch.server.actionhandler.ActionHandler;
import com.gwtplatform.dispatch.shared.ActionException;
import com.soladhoc.annonces.server.service.AnnonceDao;
import com.soladhoc.annonces.shared.service.AnnonceRequestFactory.AnnonceService;

public class SaveAnnonceActionActionHandler implements
		ActionHandler<SaveAnnonceAction, SaveAnnonceActionResult> {

	private final AnnonceService service;
	
	@Inject
	public SaveAnnonceActionActionHandler(AnnonceService service) {
		this.service = service;
	}

	@Override
	public SaveAnnonceActionResult execute(SaveAnnonceAction action,
			ExecutionContext context) throws ActionException {
		new AnnonceDao().put(action.getAnnonce());
		return new SaveAnnonceActionResult(action.getAnnonce());
	}

	@Override
	public void undo(SaveAnnonceAction action, SaveAnnonceActionResult result,
			ExecutionContext context) throws ActionException {
		new AnnonceDao().delete(action.getAnnonce());
	}

	@Override
	public Class<SaveAnnonceAction> getActionType() {
		return SaveAnnonceAction.class;
	}
	
}
